import { createRouter, createWebHashHistory } from 'vue-router'
import {userAuthStore} from "@/store/auth.js";

let router = createRouter({
    history: createWebHashHistory(),
    routes: [
        {
            path: '/',
            name: 'layout',
            redirect: '/home',
            component: () => import('@/layout/index.vue'),
            meta: {
                title: '',
                hidden: true,
                icon: '',
            },
            children: [
                {
                    path: '/home',
                    name: 'home',
                    component: () => import('@/views/home/index.vue'),
                    meta: {
                        title: '首页',
                        hidden: false,
                        icon: 'House',
                    },
                },
                {
                    path: '',
                    //component: () => import('@/views/role/index.vue'),
                    name: 'system',
                    meta: {
                        title: '系统设置',
                        hidden: false,
                        icon: 'User',
                    },
                    children: [
                        {
                            path: '/user',
                            name: 'user',
                            component: () => import('@/views/user/index.vue'),
                            meta: {
                                title: '用户管理',
                                hidden: false,
                                icon: 'User',
                            }
                        },
                        {
                            path: '/role',
                            name: 'role',
                            component: () => import('@/views/role/index.vue'),
                            meta: {
                                title: '角色管理',
                                hidden: false,
                                icon: 'User',
                            },
                        },
                        {
                            path: '/permission',
                            name: 'permission',
                            component: () => import('@/views/permission/index.vue'),
                            meta: {
                                title: '权限管理',
                                hidden: false,
                                icon: 'User',
                            }
                        }
                    ]
                }

            ],
        },
        {
            path: '/login',
            name: 'login',
            component: () => import('@/views/Login.vue'),
            meta: {
                title: '',
                hidden: true,
                icon: '',
            },
        }
    ],
})

router.beforeEach((to, from, next) => {
    const authStore = userAuthStore();
    authStore.initAuth();
    // if (to.name === "login") {
    //     authStore.$reset();
    //     localStorage.removeItem("web-auth-plat");
    //     next();
    //     return;
    // }
    // if (authStore.id === "") {
    //     next({ name: "login" });
    //     return;
    // }
    next();
})

export default router